/*
 * BaseLayout.java
 * 
 * 
 * Copyright (c) 2007 Aris Bartee
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
 * Created on Jun 7, 2007, 12:23:25 PM
 * 
 */

package afterburner.jsp;

import java.io.IOException;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * JSPs extend this class to gain Layout status.<br/>
 * The class provides the method <b>output</b>.
 * JSP Layouts should call &lt;%=output("body")%&gt;.  
 * This calls outputs the view originally called by the request
 * @author arisbartee
 */
public class Layout extends Base{


    public Layout() {
		super();
    }
   
	/**
	* @see javax.servlet.jsp.HttpJspPage#service(ServletRequest, ServletResponse)
	*/
    public void service(ServletRequest srequest,ServletResponse sresponse) throws ServletException, IOException {
		setRequestResponse(srequest,sresponse);
        outputMap = (Map<String,String>)_request.getAttribute("afterburner.outputMap");
        _jspService(_request,_response);
       
    }
   
    /**
     * Used by the JSP to output content.
     * @param name The JSP in question add contents using the name as the key.
     */
    public String output(String name){
        return outputMap.get(name);
    }

    /**
     * Used by the JSP to output content.
     * @param name The JSP in question add contents using the name as the key.
     * @param if_null A string to return if no content is available for the name.
     */
    public String output(String name, String if_null){
        String x = output(name);
        if(x == null)x = if_null;
        return x;
    }
}
